import java.util.ArrayList;
import java.util.Arrays;

/**
 * Created by cc
 * Description:
 * User: CZH
 * Date: 2022-09-29
 * Time: 17:04
 */
public class MyStack {
    private int[] elem;
    private int usedSize = 0;

    public MyStack() {
        elem = new int[10];
    }

    //是否满
    public boolean isFull() {
        if (this.usedSize == this.elem.length) return true;
        return false;
    }

    // item 入栈
    public void push(int item) {
        if (isFull()) {
            this.elem = Arrays.copyOf(this.elem, this.elem.length * 2);
        }
        this.elem[this.usedSize++] = item;
    }

    //是否空栈
    public boolean isEmpty(){
        return this.usedSize == 0;
    }

    //弹出栈顶元素
    public int pop() throws RuntimeException{
        if (isEmpty()) {
            throw new RuntimeException("空栈~");
        }
        int ret = this.elem[this.usedSize-1];
        this.usedSize--;
        return ret;
    }

    //查看栈顶元素是多少
    public int peek() throws RuntimeException{
        if (isEmpty()) {
            throw new RuntimeException("栈为空~");
        }
        return this.elem[this.usedSize-1];
    }
}
